<template>
	<view class="equipment">
		<scroll-view scroll-y="true">
			<view>
				<view class="top_equipment">
					<view :class="activeIndex==index?'top_item active':'top_item'" v-for="(item,index) in  equipment"
						:key="index" @click="clickItem(item,index)">
						<view class="title">
							{{item.title}}
						</view>
					</view>
				</view>
				<view class="top_box">
					<view class="l" @click="changeActiveName('GroupList')">
						<text>{{activeName}}({{count}}台)</text>
					</view>
					<view class="r">
						<image style="width: 24rpx;height: 24rpx;" src="/static/newProject/edit.png" mode=""></image>
						<text @click="jump('./grouping')">分组管理</text>
					</view>
				</view>
				<!-- 	<view class="top_box" @click="changeActiveName('GroupType')">
					<view class="l">
						<text>{{activeType}}</text>
						<image style="width: 7px;height: 12px;transform: rotate(90deg);"
							src="/static/newProject/equipment/icon_r.png" mode=""></image>
					</view>
					<view class="r">
						<text>类型</text>
					</view>
				</view> -->
				<view class="equipment_box">

					<view class="cenetr_box">
						<view class="r">
							<text>总收益：{{equipmentInfo.totalIncome}}</text>
						</view>
						<view class="r">
							<text>昨天收益：{{equipmentInfo.yesterIncome}}</text>
						</view>
					</view>
					<view class="equipment_list">
						<view v-for="(item,index) in list" :key="index">

							<view class="equipment_item black">
								<view class="l"
									@click="jump(`/pages/equipment/equipmentProfit?name=${item.sn}&onlineCode=${item.onlineCode}`)">
									<image :src="$fun.imgUrl(item.image)" mode=""></image>
									<view class="center_info">
										<view class="text1">
											{{item.remark}}
										</view>
										<view class="text2">
											{{item.province}}
											{{item.city}}
										</view>
										<view class="text">
											<view class="b" v-if="item.onlineStatus=='online'">

											</view>
											<!-- 			<view class="b" style="background: gray;" v-else-if="item.onlineStatus=='online'">

											</view> -->
											<view class="b" style="background: red;" v-else>

											</view>
											<view class="info">
												{{item.deviceId}}
											</view>
										</view>

									</view>
								</view>
								<view class="r">
									<view class="info">
										<text>+{{item.income}}</text>
										<text>总{{item.totalIncome}}</text>
										<text
											@click="jump(`./Kline?name=${item.deviceId}&onlineCode=${item.onlineCode}`)">查看详情</text>
									</view>
									<image src="/static/newProject/equipment/icon_r.png" mode=""></image>
								</view>
								<view class="set">
									<view  @click="jump(`./seepNetwork?deviceId=${item.deviceId}`)">测试网络>></view>
									<view @click="jump(`../networkSet/networkSet?deviceId=${item.deviceId}&name=${$fun.decorateNetwork(item.diallingType,'diallingType',deviceConfig)}`)">网络信息>></view>
								</view>
							</view>

						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import headerTop from "@/components/dacizi-headtag/dacizi-headtag.vue"
	export default {
		components: {
			headerTop
		},
		data() {
			return {
				equipment: [{
						title: '全部',
						value: '-1',
						color: '#FFFFFF'
					},
					{
						title: '在线',
						value: '0',
						color: '#00FF00'
					},
					{
						title: '离线',
						value: '1',
						color: '#A0A0A0'
					},
					{
						title: '故障',
						value: '2',
						color: '#FF0000'
					},
				],
				equipmentInfo: {
					count: 0
				},
				list: [],
				page: 1,
				limit: 20,
				activeIndex: 0,
				activeName: '全部分组',
				activeType: '',
				group_id: -1,
				pipeType: '',
				GroupList: [],
				GroupType: [],
				count: 0,
					deviceConfig: {}
			}
		},
		onReachBottom() {
			if (this.page != 1) {
				this.getUserSnList(this.page, this.limit)
			}
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('./add')
		},
		onLoad() {
			this.list = []
			this.page = 1
			this.getGroupList()
		},
		methods: {
			changeActiveName(str) {
				let data = []
				for (var i = 0; i < this[str].length; i++) {
					data.push(this[str][i].name)
				}
				uni.showActionSheet({
					itemList: data,
					success: (res) => {
						console.log(res)
						if (str == 'GroupList') {
							this.group_id = this.GroupList[res.tapIndex].id
							this.activeName = this.GroupList[res.tapIndex].name
							this.count = this.GroupList[res.tapIndex].num
						} else {
							this.pipeType = this[str][res.tapIndex].id
							this.activeType = this[str][res.tapIndex].name
						}
						this.list = []
						this.page = 1
						this.getUserSnList(this.page, this.limit)
						// this.getGroupList()
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			getUserSnList(page, limit) {
				this.$fun.ajax.post('pai/getList', {
					page,
					limit,
					// onlineCode: this.equipment[this.activeIndex].value,
					// group_id: this.group_id,
					// pipeType: this.pipeType
				}).then(res => {
					// console.log(res)
					if (res.data.data.length > 0) {
						this.list.push(...res.data.data);
						// this.addressList = res.data
						this.page++
					} else {
						if (this.page != 1) {
							// this.$fun.msg('没有更多数据了...')
						}
					}
					this.equipmentInfo = res.data
				})
			},
			clickItem(item, index) {
				this.activeIndex = index
				this.list = []
				this.page = 1
				this.getUserSnList(this.page, this.limit)
			},
			async getGroupList(onlineCode = -1) {
				await this.$fun.ajax.post('butt/groupList', {
					onlineCode,
				}).then(res => {
					this.GroupList = res.data
					this.count = res.data[0].num
					this.activeName = res.data[0].name
				})
				await this.getUserSnList(this.page, this.limit)
				await this.getConfig()
			},
			jump(url) {
				this.$fun.jump(url)
			},
			getConfig() {
				this.$fun.ajax.post('pai/getSubmit').then(res => {
					this.deviceConfig = res.data
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #EEEEEE;
	}

	.equipment {
		.top_equipment {
			padding-top: 20rpx;
			width: 100%;
			height: 88rpx;
			background: #2a80f7;
			box-sizing: border-box;
			padding: 0 0rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.top_item {
				width: 25%;
				height: 88rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-family: Microsoft YaHei;
				color: #FFFFFF;
				font-size: 30rpx;

				.num {
					margin-bottom: 20rpx;
					font-weight: bold;
				}

				.circular {
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
				}
			}

			.active {
				border-radius: 4rpx 4rpx 0px 0px;
				background: #FFFFFF;
				color: #FE5102;
			}
		}

		.top_box {
			background: #FFFFFF;
			display: flex;
			padding: 0 32rpx;
			height: 95rpx;
			align-items: center;
			justify-content: space-between;

			.l {
				display: flex;
				align-items: center;

				image {
					margin-left: 13rpx;
					margin-right: 10rpx;
					width: 33rpx;
					height: 38rpx;
				}

				text {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #333333;
				}
			}

			.r {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #2a80f7;

				image {
					margin-right: 10rpx;
				}
			}
		}

		.equipment_box {
			padding: 0rpx 30rpx;


			.cenetr_box {
				margin-top: 29rpx;
				height: 80rpx;
				background: #EEEEEE;
				border-radius: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				// padding: 0 30rpx;
				box-sizing: border-box;

				.l {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #333333;
				}

				.r {
					width: 336rpx;
					height: 80rpx;
					background: #2a80f7;
					border-radius: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #FFFFFF;

					image {
						margin-left: 90rpx;
						width: 24rpx;
						height: 14rpx;
					}
				}
			}

			.equipment_list {
				margin-top: 20rpx;

				.equipment_item {
					margin-bottom: 20rpx;
					width: 100%;
					padding: 25rpx 30rpx;
					border-radius: 10rpx;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;
					background: #FFFFFF;

					.set {
						margin-top: 20rpx;
						width: 100%;
						display: flex;
						justify-content: space-between;

						view {
							color: #2a80f7;
							font-size: 24rpx;
						}
					}

					.l {
						display: flex;

						image {
							width: 165rpx;
							height: 165rpx;
							border-radius: 10rpx;
						}

						.center_info {
							margin-left: 14rpx;
							display: flex;
							flex-direction: column;
							width: 300rpx;

							.text1 {
								font-size: 32rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #333333;
							}

							.text2 {
								margin-top: 20rpx;
								font-size: 24rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #999999;
							}

							.text {

								display: flex;
								align-items: center;

								.b {
									width: 28rpx;
									height: 8rpx;
									background: #55B953;
									border-radius: 4rpx;
								}

								.info {
									width: 277rpx; //固定宽度
									overflow: hidden; //溢出隐藏
									white-space: nowrap; //不换行
									text-overflow: ellipsis; //显示...
									font-size: 24rpx;
									font-family: Source Han Sans CN;
									font-weight: 400;
									color: #999999;
								}
							}

						}
					}

					.r {
						display: flex;
						justify-content: flex-end;
						align-items: center;

						.info {
							height: 100%;
							display: flex;
							flex-direction: column;
							justify-content: flex-start;
							text-align: right;

							text:nth-child(1) {
								font-size: 24rpx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: #FE0000;
							}

							text:nth-child(2) {
								margin-top: 30rpx;
								font-size: 24rpx;
								font-family: Adobe Heiti Std;
								font-weight: normal;
								color: #999999;
							}

							text:nth-child(3) {
								font-size: 24rpx;
								font-family: Adobe Heiti Std;
								font-weight: normal;
								color: #2a80f7;
							}

						}

						image {
							margin-left: 22rpx;
							width: 14rpx;
							height: 24rpx;
						}
					}
				}

				.gray {
					background: #F6F6F6;
					color: #CCCCCC;
				}

				.black {
					// background: #F6F6F6;
					color: #333333;
				}
			}
		}

	}

	.noneDate_box {
		margin-top: 126rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		image {
			width: 309rpx;
			height: 317rpx;
		}

		.button {
			margin: 30rpx 0;
			width: 200rpx;
			height: 60rpx;
			background: linear-gradient(-30deg, #FE555A 0%, #F99E35 100%);
			border-radius: 30rpx;
			font-size: 22rpx;
			font-family: Microsoft YaHei;
			color: #FFFFFF;
			line-height: 60rpx;
			text-align: center;
		}
	}
</style>